/**
 * 
 */
package com.bestbuy.serviceimple;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;










import com.bestbuy.dao.ProductDao;
import com.bestbuy.pojo.Product;
import com.bestbuy.pojo.ProductDetail;
import com.bestbuy.service.ProductService;

/**
 * @author Tuan
 *
 */
@Service
public class ProductServiceImpl implements ProductService{

	@Autowired
	private ProductDao productDAO;
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#GetProduct()
	 */
	@Transactional
	public List<Product> getListProduct() {
		
		return productDAO.getListProduct();
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#Search(java.lang.String, java.lang.String)
	 */
	@Transactional
	public List<Product> Search(String keySearch, String idCatagory,String Page) {
		
		return productDAO.Search(keySearch, idCatagory,Page);
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#TotalPage(java.lang.String, java.lang.String)
	 */
	@Transactional
	public int TotalPage(String keySearch, String idCatagory) {
		int count = productDAO.countProduct(keySearch, idCatagory);
		int page = count/5;
		int du = count%5;
		if(du>0)
		{
			page = page+1;
		}
		
		return page;
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#getProduct(java.lang.Integer)
	 */
	@Transactional
	public Product getProduct(Integer idproduct) {
		// TODO Auto-generated method stub
		return productDAO.getProduct(idproduct);
	}

	@Transactional
	public Product getProduct(String idProduct) {
		return productDAO.getProduct(idProduct);
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#updateProduct(com.bestbuy.pojo.Product)
	 */
	@Transactional
	public void updateProduct(Product product) {
		// TODO Auto-generated method stub
		productDAO.updateProduct(product);
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#saveProduct(com.bestbuy.pojo.Product)
	 */
	@Transactional
	public void saveProduct(Product product) {
		// TODO Auto-generated method stub
		productDAO.saveProduct(product);
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#saveProductDetail(com.bestbuy.pojo.ProductDetail)
	 */
	@Transactional
	public void saveProductDetail(ProductDetail detail) {
		// TODO Auto-generated method stub
		productDAO.saveProductDetail(detail);
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#getProductByName(java.lang.String)
	 */
	@Transactional
	public Product getProductByName(String nameProduct) {
		// TODO Auto-generated method stub
		return productDAO.getProductByName(nameProduct);
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#getListProduct(java.lang.String, java.lang.String)
	 */
	@Transactional
	public List<Product> getListProduct(String page, String isDelete) {
		// TODO Auto-generated method stub
		return productDAO.getListProduct(page, isDelete);
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#countProduct(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Transactional
	public int countProduct(String keySearch, String idCatagory, String isDelete) {
		// TODO Auto-generated method stub
		int count = productDAO.countProduct(keySearch, idCatagory, isDelete);
		int page = count/5;
		int du = count%5;
		if(du>0)
		{
			page = page+1;
		}
		
		return page;
	}
	/* (non-Javadoc)
	 * @see com.bestbuy.service.ProductService#Search(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@Transactional
	public List<Product> Search(String keySearch, String idCatagory,
			String page, String isDelete) {
		// TODO Auto-generated method stub
		return productDAO.Search(keySearch, idCatagory, page, isDelete);
	}

}
